home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11853 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: solon.com!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: const pointer confusion...
  5. Date: 26 Mar 1996 18:59:59 -0600
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4ja3uf$pe8@solutions.solon.com>
  10. References: <4j06gm$7oa@solutions.solon.com> <4j41hs$nku@solutions.solon.com> <4j6354$3ge@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4j6354$3ge@solutions.solon.com>,
  14. Kurt Watzka <watzka@stat.uni-muenchen.de> wrote:
  15.  >nausikaa:/home/kurt/src> cc cicp.c
  16.  >"cicp.c", line 6: invalid type combination
  17.  >cc: acomp failed for cicp.c
  18.  >nausikaa:/home/kurt/src> cat cicp.c
  19.  >#include <stdio.h>
  20.  >
  21.  >int main()
  22.  >{
  23.  >   int i = 42;
  24.  >   const int const *p = &i;
  25.  >
  26.  >   printf("%d\n", *p);
  27.  >   return 0;
  28.  >}
  29.  >
  30.  >I think I'd better get a new compiler, if it cannot compile such a
  31.  >simple program.
  32.  >
  33.  >AFAIK, "const int const *p;" _indeed is_ a syntax error.
  34.  
  35. No. It is a semantic error that some compilers will warn about.  A the
  36. duplicate type qualifier isn't a problem, but it could indicate that the
  37. programmer intended to do something else.
  38.  
  39. Your compiler is producing a misleading diagnostic. There is no invalid type
  40. combination here. The error is one of a redunant ``const'', which is not
  41. forbidden by the C language.
  42.  
  43. Both ``const int *p'' and ``int const *p'' are equivalent. Try feeding these to
  44. your compiler and post the results. If it doesn't accept the latter, it has a
  45. problem. It may produce a warning about an unusual order between the type
  46. specifier and the type qualifier, but it should not fail to translate, IMHO.
  47.  
  48.  
  49. -- 
  50.